package objects.base;

import org.newdawn.slick.Color;
import org.newdawn.slick.Game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

import util.instance.Instance;

/**
 * A superclass for all objects that have a position and size.
 * Contains multiple other generalized state variables.
 * 
 * @author John
 */

public class Rectangle extends Instance
{
	protected float width;
	protected float height;
	protected Color fillColor;
	
	/**
	 * Initializes a rectangular object of given size at the given position.
	 * 
	 * @param initX - The initial X position.
	 * @param initY - The initial Y position.
	 * @param initWidth - The initial width of the object.
	 * @param initHeight - The initial height of the object.
	 */
	public Rectangle(float initX, float initY, float initWidth, float initHeight)
	{
		// Initialize position and size
		x = initX;
		y = initY;
		width = initWidth;
		height = initHeight;
		//bestColor = Color.black;
		// Pick a random color to fill the box with
		fillColor = new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
		//sprite=new util.resource.Sprite(ResourceManager.getImage("test.png"),43);
		//sprite.setImageSpeed(.2f);
	}
	
	/**
	 * Renders either the sprite given to the object or a place holder rectangle.
	 * 
	 * @param gc - the current game container.
	 * @param game - the current game.
	 * @param g - the current graphics.
	 */
	public void render(GameContainer gc, Game game, Graphics g)
	{
		// If the rectangle has a sprite attached to it, draw that
		if (sprite != null)
		{
			sprite.getImage().draw(x,y,width,height);
		}
		// Otherwise, draw a rectangle in its stead
		else
		{
			// Draw the box's fill color
			g.setColor(fillColor);
			g.fillRect((int)x,(int)y,width,height);
			// Draw the box's outline
			g.setColor(Color.black);
			g.drawRect((int)x,(int)y,width,height);
		}
	}
	
	/**
	 * Returns the width of the object.
	 * @return - A float value containing the width of the object.
	 */
	public float getWidth()
	{
		return width;
	}
	
	/**
	 * Returns the height of the object.
	 * @return - A float value containing the height of the object.
	 */
	public float getHeight()
	{
		return height;
	}
}
